
<template>
  <el-dialog v-model="ifShow" title="重发" width="1000" :before-close="handleCancel">
    <el-form ref="ruleForm" :model="formData" :rules="rules" label-width="auto" class="demo-ruleForm" status-icon>
      <el-form-item label="邮箱" prop="email">
        <el-input placeholder="请输入" v-model="formData.email" />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="handleCancel">取消</el-button>
        <el-button type="primary" @click="handleOk">确认</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import CommonApi from "@/api/common";
import OrderApi from "@/api/order";
import { ref } from "vue";

const ruleForm = ref(null);
const orderId = ref();
let formData = ref({
  invoiceId: "",
  email: "",
});
const rules = reactive({
  invoiceType: [{ required: true, message: "请选择", trigger: "blur" }],
  title: [{ required: true, message: "请输入", trigger: "blur" }],
});

const ifShow = ref(false);
const emit = defineEmits(["success"]);
function edit(row: any) {
  nextTick(() => {
    ifShow.value = true;

    formData.value = {
      invoiceId: "",
      email: "",
    };
    row.invoiceId = row.id;
    //赋值
    Object.assign(formData.value, row);
  });
}

/**
 * 确定按钮点击事件
 */
async function handleOk() {
  await ruleForm.value.validate((valid, fields) => {
    if (valid) {
      let data = {
        invoiceId: formData.value.invoiceId,
        email: formData.value.email,
      };
      OrderApi.resendInvoice(data).then((res) => {
        if (res.code == 0) {
          emit("success");
          handleCancel();
          ElMessage.success(res.message);
          ruleForm.value.resetFields();
        }
      });
    } else {
      console.log("error submit!", fields);
    }
  });
}

/**
 * 取消按钮回调事件
 */
function handleCancel() {
  ifShow.value = false;
}

defineExpose({
  edit,
});
onMounted(() => {});
</script>
<style lang="scss" scoped>
.btn_case {
  padding: 14px 0;
  .el-button {
    width: 100px;
    margin: 14px 14px 14px 0;
  }
}
</style>
